package com.bawei.shixun.base

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.bawei.shixun.R
import java.lang.reflect.ParameterizedType

abstract class BaseActivty<V:ViewModel,D:ViewDataBinding>(private var layout:Int) :AppCompatActivity(){
    lateinit var mViewmodel:V
    lateinit var mDing:D
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mDing=DataBindingUtil.setContentView(this,layout)
        mDing.lifecycleOwner=this
        var type=javaClass.genericSuperclass as ParameterizedType
        var vClass=type.actualTypeArguments[0] as Class<V>
        mViewmodel=ViewModelProvider(this)[vClass]
        initview()
        dataObser()
    }

    abstract fun dataObser()

    abstract fun initview()

    override fun onDestroy() {
        super.onDestroy()
    }
}